package com.yan.demo;

import com.yan.domain.Book;

public class OOPDemo6 {
    public static void main(String[] args) {
        Book[] all = new Book[5];

        all[0] = new Book(1, "《从入门到精通》", "张三", 88, 100, 1000, "static/img/1.jpg");
        all[1] = new Book(2, "《从入门到放弃》", "李四", 89, 200, 800, "static/img/1.jpg");
        all[2] = new Book(3, "《从入门到脱发》", "王五", 56, 10, 500, "static/img/1.jpg");
        all[3] = new Book(4, "《从入门到吃药》", "赵六", 100, 180, 900, "static/img/1.jpg");
        all[4] = new Book(5, "《从入门到升仙》", "钱七", 99, 0, 1000, "static/img/1.jpg");

        for (int i = 0; i < all.length; i++) {
            System.out.println(all[i].getInfo());
        }

        System.out.println("按销售量排序");
        for (int i = 0; i < all.length - 1; i++) {
            for (int j = 0; j < all.length - 1 - i; j++) {
                if (all[j].getSales() < all[j + 1].getSales()) {
                    Book temp = all[j];
                    all[j] = all[j + 1];
                    all[j + 1] = temp;
                }
            }
        }
        for (int i = 0; i < all.length; i++) {
            System.out.println(all[i].getInfo());
        }
    }
}
